package com.qf.iostream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class InputStreamTest {

	
	public static void main(String[] args) {
		
		String path = "D:\\Workspace\\Practice\\src\\laoyouji2.txt";
		inputStreamByTxtFile(path);
		
	}
	
	
	public static void inputStreamByTxtFile(String path) {
		
		
		
		
		
		try {
		File f1 = new File(path);
		
		//读入
		FileInputStream fileInput = new FileInputStream(f1);
		
		//读取字节个数
		long m=fileInput.available();
		System.out.println(m);
		
		
		
		
		byte[] buff =new byte[10];
		int len = -1;
		
		//读取的原理应该就是一次读取一个buff数组字节的内容，10个字符，当没有字符时返回-1
		System.out.println("一次read的读取："+fileInput.read(buff));
		
		//while读取时候，就已经少了10个字符的内容，被上一次读取给截取掉了
		while((len=fileInput.read(buff))!=-1) {
			//不过这里write没明白，0？，len？
			System.out.write(buff,0,len);
		}
			
			
		}catch(FileNotFoundException e1) {
			System.out.println("文件没找到！"+" "+e1.getMessage());
			
		}catch(IOException e2) {
			System.out.println("IO流异常！"+" "+e2.getMessage());
			
		}catch(Exception e) {
			System.out.println("未知异常！");
			
		}finally{
			
		}
		
		
		
	}
	
}
